package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @GetMapping("/GetPayment/{id}")
    public CommonResult<Payment> GetPayment(@PathVariable("id") Long id){
        log.info("id{}:"+id);
        Payment payment = paymentService.selectById(id);
        if (payment !=null){
            System.out.println("...");
        }
        return new CommonResult(200,"查询成功："+"\t 端口号为：" + serverPort,payment);
    }

    @PostMapping("/CreatePayment")
    public CommonResult<Payment> CreatePayment(@RequestBody Payment payment){
        int result = paymentService.insertPayment(payment);
        return new CommonResult(200,"插入成功：" + result,null);
    }

    /**
     * 测试gateWay网关
     * @return
     */
    @GetMapping("/get")
    public String PaymenGet(){

        return serverPort;
    }

    @GetMapping("/lb")
    public String PaymenLb(){

        return serverPort;
    }

}
